#include <iostream>
using std::cout;
using std::endl;

//复数
class Complex
{
public:
    Complex(int real,int image)
    : _real(real)
    , _image(image)
    {}

    void print() const{
        cout << _real << " + " << _image << "i" << endl;
    }

    Complex & operator+=(const Complex & rhs){
        _real += rhs._real;
        _image += rhs._image;
        return *this;
    }

    
    Complex & operator++(){
        cout << "前置++重载函数" << endl;
        ++_real;
        ++_image;
        return *this;
    }

    //后置++与前置++的操作数一样
    //在重载函数的参数列表中加上int,以示区分
    Complex operator++(int){
        cout << "后置++重载函数" << endl;
        Complex temp(*this);
        ++_real;
        ++_image;
        return temp;
    }


    friend
    Complex operator+(const Complex & lhs,const Complex & rhs);
private:
    int _real;
    int _image;
};

Complex operator+(const Complex & lhs,const Complex & rhs){
    return Complex(lhs._real + rhs._real, lhs._image + rhs._image);
}

void test1(){
    int num = 10;
    cout << &num << endl;
    cout << &(++num) << endl;
    cout << num << endl;
}


void test2(){
    Complex cx1(3,8);
    Complex cx2(6,4);
    cx1 += cx2;
    /* cx1.operator+=(cx2);//本质 */
    cx1.print();//9 + 12i


    ++cx1;
    cx1.operator++();//本质形式
    cx1.print();//11 + 14i

    (cx1++).print();//11 + 14i
    cx1.print();//12 + 15i
}



int main(void){
    test2();
    return 0;
}
